package org.transfer.datasource;

import com.alibaba.druid.pool.DruidDataSource;

import java.util.Map;

/**
 * Created by 10248 on 2018/12/1.
 */
public class CreateDatasource {
    public void createDatasourec(String url,String username,String pwd,String driverClassName,String sourceName){
        /**
         * 根据slave数据源获取目标数据库信息
         */
        DruidDataSource dynamicDataSource = new DruidDataSource();
        dynamicDataSource.setDriverClassName(driverClassName);
        dynamicDataSource.setUrl(url);
        dynamicDataSource.setUsername(username);
        dynamicDataSource.setPassword(pwd);
        /**
         * 创建动态数据源
         */
        Map<Object, Object> dataSourceMap = DynamicDataSource.getInstance().getDataSourceMap();
        dataSourceMap.put(sourceName, dynamicDataSource);
        DynamicDataSource.getInstance().setTargetDataSources(dataSourceMap);
        
    }
}
